package com.softserveinc.lahire.builders;

import java.io.IOException;

public class SimpleResponseBuilder extends ResponseBuilder {

	public void buildHeaders() {

		StringBuilder headers = new StringBuilder();
		headers.append("HTTP/1.1 ");
		headers.append(response.getStatusCode());
		headers.append(" ");
		headers.append("OK");
		headers.append("\n");
		headers.append("Content-Length: " + response.getContentLength() + "\n");
		headers.append("Server: " + response.getServer() + "\n");
		headers.append("Connection: " + response.getConnection() + "\n");
		headers.append("Content-Type: " + response.getContentType() + "\n");

		if (response.getCookie() != null) {
			headers.append("Set-Cookie: " + response.getCookie());
		}

		headers.append("\n");

		try {
			response.write(headers.toString().getBytes());
		} catch (IOException e) {
			System.out.println(e.getMessage());
		}
	}

	public void appendBody(byte[] body) {
		try {
			response.write(body);
		} catch (IOException e) {
			System.out.println(e.getMessage());
		}
	}

}
